import { makeAutoObservable, } from "mobx";
import { UserInfo } from "../services/LoginService";
import { LocalStorageService } from '../utils/storage';

class UserStore {
  public userInfo?: UserInfo;
  public loginModalVisible: boolean = false;

  constructor() {
    makeAutoObservable(this);
  }

  public init() {
    let _userInfo: UserInfo = LocalStorageService.get('_userInfo');
    console.log("_userInfo", _userInfo)
    this.userInfo = _userInfo;
  }


  public updateUser(_userInfo: UserInfo) {
    this.userInfo = _userInfo;
    if (_userInfo) {
      LocalStorageService.set('_userInfo', _userInfo)
    }
  }

  public logout() {
    this.userInfo = undefined;
    LocalStorageService.remove("_userInfo");
    LocalStorageService.remove("token");
  }
}

const userStore = new UserStore();

export { userStore };